%%% -------------------------------------------------------------------
%%% Author  : tangj
%%% Description :
%%%
%%% Created : 2012-11-1
%%% -------------------------------------------------------------------
-module(tcp_listener_sup).

-behaviour(supervisor).
%% --------------------------------------------------------------------
%% Include files
%% --------------------------------------------------------------------

%% --------------------------------------------------------------------
%% External exports
%% --------------------------------------------------------------------
-export([]).

%% --------------------------------------------------------------------
%% Internal exports
%% --------------------------------------------------------------------
-export([
		 start_link/1,
		 init/1
		]).

%% --------------------------------------------------------------------
%% Macros
%% --------------------------------------------------------------------
-define(SERVER, ?MODULE).

%% --------------------------------------------------------------------
%% Records
%% --------------------------------------------------------------------

%% ====================================================================
%% External functions
%% ====================================================================

start_link(Port) ->
    supervisor:start_link(?MODULE, {Port}).

%% ====================================================================
%% Server functions
%% ====================================================================
%% --------------------------------------------------------------------
%% Func: init/1
%% Returns: {ok,  {SupFlags,  [ChildSpec]}} |
%%          ignore                          |
%%          {error, Reason}
%% --------------------------------------------------------------------
init({Port}) ->
	{ok, {{one_for_all, 10, 10},
	  [
	   {tcp_acceptor_sup, 
		{tcp_acceptor_sup, start_link, []},
		transient, infinity, supervisor, [tcp_acceptor_sup]},
	   
	   {lists:concat([tcp_listener_,Port]),
		{tcp_listener, start_link, [Port]},
		transient, 16#ffffffff, worker, [tcp_listener]}
	  ]}
	}.

%% ====================================================================
%% Internal functions
%% ====================================================================

